package com.hawk.eye.server.convert;

import com.hawk.eye.server.domain.dto.req.RepairWorkOrderReqDTO;
import com.hawk.eye.server.domain.dto.resp.RepairApiRespDTO;
import com.hawk.eye.server.domain.dto.resp.RepairWorkOrderRespDTO;
import com.hawk.eye.api.storage.dto.ServiceLogRespDTO;
import com.hawk.eye.server.domain.po.RepairWorkOrder;
import com.hawk.eye.server.domain.vo.req.RepairWorkOrderReqVO;
import com.hawk.eye.server.domain.vo.resp.RepairWorkOrderRespVO;
import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @author zd
 */
@Mapper
@DecoratedWith(RepairWorkOrderConvert.RepairWorkOrderConvertDecorator.class)
public interface RepairWorkOrderConvert {

    RepairWorkOrderConvert INSTANCE = Mappers.getMapper(RepairWorkOrderConvert.class);

    RepairWorkOrderReqDTO to(RepairWorkOrderReqVO reqVO);

    RepairWorkOrderRespVO to(RepairWorkOrderRespDTO respDTO);

    RepairWorkOrderRespDTO to(RepairWorkOrder repairWorkOrder);

    @Mapping(source = "repairWorkOrder.id", target = "id")
    @Mapping(source = "repairWorkOrder.baseAlarmId", target = "baseAlarmId")
    @Mapping(source = "repairWorkOrder.traceId", target = "traceId")
    @Mapping(source = "repairWorkOrder.stackHash", target = "stackHash")
    @Mapping(source = "repairWorkOrder.createTime", target = "createTime")
    RepairWorkOrderRespDTO to(RepairWorkOrder repairWorkOrder, RepairApiRespDTO repairApiRespDTO, ServiceLogRespDTO detail);


    public abstract class RepairWorkOrderConvertDecorator implements RepairWorkOrderConvert {

        @Override
        public RepairWorkOrderRespDTO to(RepairWorkOrder repairWorkOrder, RepairApiRespDTO repairApiRespDTO, ServiceLogRespDTO detail) {
            RepairWorkOrderRespDTO respDTO = new RepairWorkOrderRespDTO();
            if (repairWorkOrder != null) {
                respDTO.setId(repairWorkOrder.getId());
                respDTO.setNodeUser(repairWorkOrder.getNodeUser());
                respDTO.setBaseAlarmId(repairWorkOrder.getBaseAlarmId());
                respDTO.setRepairApiId(repairWorkOrder.getRepairApiId());
                respDTO.setTraceId(repairWorkOrder.getTraceId());
                respDTO.setStackHash(repairWorkOrder.getStackHash());
                respDTO.setDescription(repairWorkOrder.getDescription());
                respDTO.setStatus(repairWorkOrder.getStatus());
                respDTO.setWorkOrderName(repairWorkOrder.getWorkOrderName());
                respDTO.setCreateTime(repairWorkOrder.getCreateTime());
            }
            if (detail != null) {
                respDTO.setAlarmTime(detail.getAlarmTime());
                respDTO.setChargeUserId(detail.getChargeUserId());
                respDTO.setChargeUserName(detail.getChargeUserName());
                respDTO.setErrorFileName(detail.getErrorFileName());
                respDTO.setRequestUri(detail.getRequestUri());
                respDTO.setServiceCnName(detail.getServiceCnName());
                respDTO.setServiceId(detail.getServiceId());
                respDTO.setServiceZnName(detail.getServiceZnName());
                respDTO.setLogMessage(detail.getLogMessage());
            }
            if (repairApiRespDTO != null) {
                respDTO.setRepairApiName(repairApiRespDTO.getName());
                respDTO.setRepairDesc(repairApiRespDTO.getRepairDesc());
                respDTO.setReqType(repairApiRespDTO.getReqType());
                respDTO.setReqUri(repairApiRespDTO.getReqUri());
                respDTO.setReqBody(repairApiRespDTO.getReqBody());
                respDTO.setProblemList(repairApiRespDTO.getProblemList());
            }
            return respDTO;
        }
    }


}